home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / C and C++ / Libraries / objects in c ƒ / Name Sources / NameSpace.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-03-06  |  1.5 KB  |  77 lines  |  [TEXT/KAHL]

  1. /*    
  2.  *        NameSpace abstract class
  3.  *
  4.  *        Nested scoping name space; a kind of HashTable.  
  5.  *
  6.  *            Copyright © John Wainwright 1988
  7.  *
  8.  *    SuperClasses :
  9.  *                    HashTable
  10.  *  Instance Vars :
  11.  *                    freeList
  12.  *    Class Vars :
  13.  *    
  14.  *    Methods :
  15.  *                    get    k        - gets the closest keyed item
  16.  *                    freePart    - get the free namespace
  17.  *                    enterScope     - add a new scope nesting
  18.  *                    leaveScope    - exit to next level of scoping
  19.  *    Class Methods :
  20.  *
  21.  */
  22.  
  23. #include "oic.h"
  24. #include "generics.h"
  25. #include "names.h"
  26.  
  27. class         NameSpace;                /* the NameSpace class                 */
  28. typedef object namespace;
  29.  
  30. struct NameSpace_i                    /* NameSpace instance structure        */
  31. {
  32.     namespace    frees;                /* free namespaces                    */
  33. };
  34. typedef struct NameSpace_i NameSpace_i;
  35.  
  36. /* -------------------- NameSpace Instance methods ------------------- */
  37.  
  38. method object
  39. _get(self, n, key)
  40.     namespace                self;
  41.     register NameSpace_i    *n;
  42.     register object            *key;
  43. {
  44.     register object    val;
  45.  
  46.     val = Super(self, *key);
  47.     return (val != NULL) ? val : get(n->frees, *key);
  48. }
  49.  
  50. method object
  51. _freePart(self, n)
  52.     namespace                self;
  53.     register NameSpace_i    *n;
  54. {
  55.     return n->frees;
  56. }
  57.  
  58. method object
  59. _enterScope(self, n)
  60.     namespace                self;
  61.     register NameSpace_i    *n;
  62. {
  63.     return New(NameSpace, self);
  64. }
  65.  
  66. /* ------------------- Init the NameSpace class ---------------------- */
  67.  
  68. InitNameSpaceClass()
  69. {
  70.     NameSpace = NewClass(sizeof(NameSpace_i), 0, "NameSpace", HashTable, END);
  71.     AddMethods(NameSpace,
  72.         getGeneric,         _get,
  73.         freePartGeneric,     _freePart,
  74.         END);
  75. }
  76.  
  77.